using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwDeferredRS
{
    /// <summary>
    /// A simple base map feature
    /// </summary>
    public class BaseMapFusion : AbstractFusion
    {
        public BaseMapFusion()
        {
            AddPreprocessor(new Preprocessor("BASEMAP_UV", 1, 3, 1, "UV channel (1-3) for baseMap."));

            // param baseMap
            AddParameter(
                new Texture2dParamter("baseMap", "baseMapSamp")
                .SetSRGBTexture(true)
                .SetUserData("fragment")
                .SetDesc("RGB: diffuse; A: gloss")
                );
        }

        public override string Name
        {
            get { return "BaseMap"; }
        }

        public override string Desc
        {
            get { return ""; }
        }

        public override Stage Stage
        {
            get { return Stage.AlbedoGloss; }
        }

        public override int UVChannelCount
        {
            get { return GetPreprocessor("BASEMAP_UV").Value; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "vec4 baseMap = tex2D(baseMapSamp, pipeline.Texcoord[BASEMAP_UV-1]);");
            AddLine(b, "pipeline.Albedo *= baseMap.rgb;");
            AddLine(b, "pipeline.Gloss *= baseMap.a;");
        }
    }
}